$(function(){
	//导航点击函数
	$.Huitab("#tab_demo .myTabBar span","#tab_demo .myTabCon","myCurrent","click","0");
	
})

function layer_open(title,url){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}

function setRtMerchant(i) {
    if (i == 0) {
        $("#rt-merchant-mer").show();
        $("#rt-merchant-per").hide();
    }
    else {
        $("#rt-merchant-mer").hide();
        $("#rt-merchant-per").show();
    }
}

function setPnrMerchant(i) {
    if (i == 0) {
        $("#pnr-merchant-mer").show();
        $("#pnr-merchant-per").hide();
    }
    else {
        $("#pnr-merchant-mer").hide();
        $("#pnr-merchant-per").show();
    }
}

function RTResultSubmit() {
    var rt = $.trim($("#rt").val());
    if (rt == "") {
        layer.open({
            title: '提示',
            content: 'RT信息不能为空！ '
        });
        $("#rt").focus();
        return;

    }
    var consumerClass = $('input[name="rtMerchantRadio"]:checked ').val();
    var personInfo = $.trim($("#rtPersonInfo").val());
    var clientId = $("#rtClientId").val();
    var clientName = $("#rtClientName").val();
    var officeNo = $("#rtOfficeNo").val();
    if (consumerClass == 0) {
        if (clientName=="" || clientId == "") {
            layer.open({
                title: '提示',
                content: '请选择存在的商户信息！ '
            });
            $("#rtClientName").focus();
            return;
        }
    }
    else {
        if (personInfo == "") {
            layer.open({
                title: '提示',
                content: '个人信息不能为空 '
            });

            $("#rtPersonInfo").focus();
            return;
        }
    }
    if (officeNo == "") {
        layer.open({
            title: '提示',
            content: '请选择Office号'
        });
        $("#rtOfficeNo").focus();
        return false;
    }
    var data = {
        "rt": rt,
        "consumerClass" : consumerClass,
        "clientId" : clientId,
        "personInfo" : personInfo,
        "officeNo" : officeNo
    };
    $.post("../order/saveByRt", data, function (msg) {
    	result = jQuery.parseJSON(msg);
        if (result.success) {
        	 $("#rtForm")[0].reset();
        	//creatIframe(_href,_titleName);
        	creatIframe("order/detail?orderId=22333","订单详情");
        	//layer_open("订单详情","../order/detail?orderId=22333");
        } else {
            layer.open({
                title: '提示',
                content: '创建订单失败：' + result.message
            });
        }
        return false;
    }).error(function () { 
    	layer.open({
            title: '提示',
            content: '系统错误！'
        });
    });
}

function PNRResultSubmit() {
    var pnr = $.trim($("#pnr").val()).toUpperCase();
    var consumerClass = $('input[name="pnrMerchantRadio"]:checked').val();
    var personInfo = $.trim($("#pnrPersonInfo").val());
    var clientName = $("#pnrClientName").val();
    var clientId = $("#pnrClientId").val();
    var officeNo = $("#pnrOfficeNo").val();
    if (consumerClass == 0) {
        if (clientName=="" || clientId == "") {
            //alert("请选择商户信息！");
            layer.open({
                title: '提示',
                content: '请选择存在的商户信息! '
            });
            $("#pnrClientName").focus();
            return;
        }
    }
    else {
        if (personInfo == "") {
            //alert("个人信息不能为空！");
            layer.open({
                title: '提示',
                content: '个人信息不能为空 '
            });
            $("pnrPersonInfo").focus();
            return;
        }
    }
    if (pnr == "") {
        //alert("PNR不能为空！");
        layer.open({
            title: '提示',
            content: 'PNR不能为空！ '
        });
        $("#pnr").focus();
        return;
    }

    reg = /^[A-Z0-9]{6}$/;
    if (!reg.test(pnr)) {
        //alert("请输入正确的pnr!");
        layer.open({
            title: '提示',
            content: '请输入正确的PNR! '
        });
        $("#pnr").focus();
        return false;
    }
    if (officeNo=="") {
        layer.open({
            title: '提示',
            content: '请选择Office号 '
        });
        $("#pnrOfficeNo").focus();
        return false;
    }
    var data = {
        "pnr": pnr,
        "consumerClass": consumerClass,
        "clientId": clientId,
        "personInfo": personInfo,
        "officeNo": officeNo
    };
    $.post("../order/saveByPnr", data, function (msg) {
    	result = jQuery.parseJSON(msg);
        if (result.success) {
//        	layer.open({
//                title: '提示',
//                content: '创单订单成功'
//            });
        	$("#pnrForm")[0].reset();
        	//creatIframe(_href,_titleName);
        	creatIframe("order/detail?orderId="+result.obj,"订单详情");
        	//layer_open("订单详情","../order/detail?orderId="+result.obj);
        } else {

            layer.open({
                title: '提示',
                content: '创单订单失败：' + result.message 
            });
        }
        return false;
    }).error(function () { 
    	 layer.open({
             title: '提示',
             content: '系统错误！' 
         });
    });
}
